<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>待我审批</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all" />
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript" src="/static/layui/layui.js"></script>
    <script type="text/javascript" src="/static/js/base.js"></script>
<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>待我审批</cite>
        </a>
      </span>
</div>
<div class="x-body">
    <div style="margin-bottom: 18px">
        <div class="layui-row" style="margin-bottom: 18px">
            <div class="layui-form">
                <div class="layui-input-inline">

                    <div class="layui-input-inline" style="width: 150px">
                        <input class="layui-input" id="keyword01" placeholder="请输入名称" style="width: 150px">
                    </div>
                    <button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
                </div>
            </div>
        </div>
        <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
    </div>
</div>
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">审核</a>
</script>
<script>

    function createTime(v){
        var date = new Date(v);
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        m = m<10?'0'+m:m;
        var d = date.getDate();
        d = d<10?("0"+d):d;
        var h = date.getHours();
        h = h<10?("0"+h):h;
        var M = date.getMinutes();
        M = M<10?("0"+M):M;
        var str = y+"-"+m+"-"+d+" "+h+":"+M;
        return str;
    }

    $(document).ready(function () {
        var time = new Date();
        var day = ("0" + time.getDate()).slice(-2);
        var month = ("0" + (time.getMonth() + 1)).slice(-2);
        var today = time.getFullYear() + "-" + (month);
        $('#dateTime').val(today);
    })
    layui.use(['table','layer','upload','form','laydate'], function(){
        var table = layui.table;
        var form=layui.form;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#date1',
            value:new Date()
        });
        laydate.render({
            elem: '#date2'
        });
        laydate.render({
            elem: '#date3',
            type: 'month',
            value: new Date(),
            done:function(value, date, endDate) {
                $('#dateTime').val(value);
            }
        });
        var $ = layui.jquery, active = {
            reload:function () {

                var dateTime = $('#dateTime').val()

                if (dateTime.length < 4) {
                    var time = new Date();
                    var day = ("0" + time.getDate()).slice(-2);
                    var month = ("0" + (time.getMonth() + 1)).slice(-2);
                    var today = time.getFullYear() + "-" + (month);
                    dateTime = today;
                }
                table.reload('contentTable',{
                    method:'get'
                    ,where:{
                        'stockId':$("#keyword1").val(),
                        'date':dateTime
                    }
                    ,page: {
                        curr: 1//重新从第 1 页开始
                    }
                });
            }
        }
        table.render({
            elem: '#tableList'
            ,id:'contentTable'
            ,url: '/forMySponsor/queryForMySponsorPage'
            ,toolbar: '#toolbar'
            ,where:{
                'completeStatus':0
            }
            ,cols: [
                [ //表头
                    {field:'uid',title:'序号',type:'numbers',align:'center'}
                    ,{field: 'realName', title: '申请人'}
                    ,{field: 'requestType', title: '申请类型',templet:function (row) {
                        if (row.requestType.trim() == 'qj'){
                            return '请假申请'
                        }else if (row.requestType.trim() == 'ty'){
                            return '通用申请'
                        }else if (row.requestType.trim() == 'bk'){
                            return '补卡申请'
                        }
                    }}
                    ,{field: 'createDate', title: '发起时间',templet:function (row) {
                        return createTime(row.createDate);
                    }}
                    ,{field: 'completeStatus', title: '状态',templet:function (row) {
                        if (row.completeStatus == 0){
                            return '未审核'
                        } else if (row.completeStatus == 1){
                            return '通过'
                        }else if (row.completeStatus == 2){
                            return '未通过'
                        }
                    }}
                    , {field: 'remark', title: '操作',  toolbar: "#toolBar"}
                ]
            ]
            , page: true
            ,totalRow: true
            ,done : function(res, curr, count){
                $('th').css({
                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
                })
            }
        });

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.layui-col-md12 .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.select .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听工具条
        table.on('tool(tableList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                var requestId = data.requestId;
                var requestType = data.requestType;
                if (requestType == 'qj'){
                    window.location.href = '/leaveRequest/queryLeave/'+requestId;
                }if (requestType == 'ty'){
                    window.location.href = '/baseRequest/queryBase/'+requestId;
                }
            }
        });

        $("#add").click(function(){
            $("#brand1").hide()
            $("#brand2").hide()
            layer.open({
                type: 1 ,				//Page层类型
                area: ['540px', '520px'] 	//宽  高
                ,title: '新增'
                ,shade: 0.6 			//遮罩透明度
                ,maxmin: true 			//允许全屏最小化
                ,anim: 1 				//0-6的动画形式，-1不开启
                ,content: $('#addDivID')
                ,success: function(){
                    //$("input[name='createDate']").val("");
                    $("input[name='wareHouseName']").val("");
                    $("textarea[name='wareHouseIp']").val("");
                    $("textarea[name='wareHousePort']").val("");
                    form.render();
                }
            });
        });
        //批量删除
        $("#del").click(function(){
            var rowData = table.checkStatus('contentTable');
            var data = rowData.data;
            var idArr = new Array();
            if(data.length == 0){
                layer.alert("请至少选择一条记录！",{icon :5})
            } else {
                for(var i=0;i < data.length;i++){
                    idArr[i] = data[i].wareHouseId;
                }
                $.ajax({
                    type:'post',
                    url:'/wareHouse/delete',
                    data:{"idArr" : idArr},
                    success:function(data){
                        layer.confirm('确定删除吗？', function(){
                            if(data > 0){
                                layer.msg('删除成功',{icon:6})
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                                setTimeout(function(){
                                    window.location.reload();
                                },2000);
                            }else{
                                layer.msg('删除失败',{icon:5})
                                location.reload();
                            }
                        });
                    }
                });
            }
        });

        form.verify({
            wareHouseName:function (value, item) {
                if(value.trim() == ''){
                    return '不能为空';
                }
            },
            wareHouseIp:function (value, item) {
                if(value.trim() == ''){
                    return '不能为空';
                }
            },
            wareHousePort:function (value, item) {
                if(value.trim() == ''){
                    return '不能为空';
                }
            },
            wareHouseUrl:function (value, item) {
                if(value.trim() == ''){
                    return '不能为空';
                }
            },
            wareHouseNumber:function (value, item) {
                if(value.trim() == ''){
                    return '不能为空';
                }
            }
        })

        /**  data:{itemName:"12",startDate:'2019-09-20'},
         * 通用表单提交(AJAX方式),totalMoney:100,startDate:'2019-09-20',dueDate:'2019-09-20'
         */
        form.on('submit(addForm)', function () {

            var r=document.getElementsByName("role");
            var role=[];
            for(var i=0;i<r.length;i++){
                if(r[i].checked){
                    console.info(r[i].value);
                    role.push(r[i].value);
                }
            }
            var data = $.param({'role':role}) + '&' + $('#addFormID').serialize()
            $("#subBtn").attr("disabled",true);
            $.ajax({
                type:'post',
                url:'/user/addUser',
                data:$('#addFormID').serialize(),
                cache:false,
            }).done(
                function(res) {
                    if (res > 0) {
                        layer.msg('新增成功',{icon:6})
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function() {
                    layer.msg('新增失败',{icon:5})
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        })
    });
</script>
</body>

</html>
